package com.shxy.entity.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.shxy.util.converter.AbstractEnumConverter;
import com.shxy.util.converter.IEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.lang.Nullable;

import java.util.Random;

/**
 * 员工类型
 */
@Getter
@AllArgsConstructor
public enum EmployeeType implements IEnum<String> {
    ZAIGANG("01", "在岗职工"),
    TUIYANG("02","退养人员"),
    TUIXIU("03","退休人员"),

    ;
    private String code;
    private String name;

    /**
     * 类型转换器
     */
    public static class Converter extends AbstractEnumConverter<EmployeeType, String> {
        public Converter() {
            super(EmployeeType.class);
        }
    }


    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    @Nullable
    public static EmployeeType resolve(String name) {
        for(EmployeeType degreeEnum: EmployeeType.values()) {
            if(name.equals(degreeEnum.getName())){
                return degreeEnum;
            }
        }
        return null;
    }

    private static Random r = new Random();

    public static EmployeeType random() {
        return EmployeeType.values()[r.nextInt(3)];
    }
}
